import { defineStore } from "pinia";
import { GlobalState } from "@/stores/interface";
import { typeStatus } from "@/interface/public";

export const useGlobalStore = defineStore({
  id: "global",
  // 修改默认值之后，需清除 localStorage 数据
  state: (): GlobalState => ({
    messageStatus: "success",
    message: "",
    loading: false,
    modalLoading: false,
    basicColor: {
      primary: "#3A75C5",
      primary_plain: "#ECF5FF"
    }
  }),
  actions: {
    // 清空消息
    clearMessage() {
      this.messageStatus = "";
      this.message = "";
    },
    // 设置消息
    setMessage(message: string = "操作成功", messageStatus: typeStatus["message"] = "success") {
      this.messageStatus = messageStatus;
      this.message = message;
      console.log(this.messageStatus, this.message, "this.message");
    },
    setColor(themeType) {
      switch (themeType) {
        case "blue-theme":
          this.basicColor.primary = "#3A75C5";
          break;
        case "jade-theme":
          this.basicColor.primary = "#c04851";
          break;
        case "orange-theme":
          this.basicColor.primary = "#FF7052";
          break;
        default:
          this.basicColor.primary = "#303133";
          break;
      }
    },
    setPrimaryPlainColor(themeType) {
      switch (themeType) {
        case "blue-theme":
          this.basicColor.primary_plain = "#ECF5FF";
          break;
        case "jade-theme":
          this.basicColor.primary_plain = "rgba(192, 72, 81, 0.2)";
          break;
        case "orange-theme":
          this.basicColor.primary_plain = "#fef0f0";
          break;
        default:
          this.basicColor.primary_plain = "#f1f1f1";
          break;
      }
    }
  }
});
